package com.huonan.designpattern;

import java.util.function.Consumer;

/**
 * @Description Consumer：场景
 * 方法a需要对变量str参数进行操作，但是具体执行在方法b中
 * 此时可以把变量想要执行的操作命名为consumer，然后传递给b
 * 总结：consumer 定义执行逻辑，然后作为参数传递给方法执行
 * @Author lxp
 * @Date 2023/3/24 下午4:15
 * @Version V1.0
 **/


public class ConsumerAndThen {
    public static void main(String[] args) {
        // Supplier<String> supplier2 = () -> "Hello World!";
        // Consumer<String> consumer1 = c -> System.out.println(c.toLowerCase());
        // Consumer<String> consumer2 = c -> System.out.println(c.toUpperCase());
        // consumer1.accept(supplier2.get());
        // //多次消费操作
        // consumer1.andThen(consumer2).accept(supplier2.get());
        a();
    }

    public static void a() {

        Consumer<String> consumer1 = c -> System.out.println("小写: "+c.toLowerCase());
        Consumer<String> consumer2 = c -> System.out.println("大写写: "+c.toUpperCase());
        //b(consumer1,consumer2);
         b(consumer1);
    }

    public static void b(Consumer<String> consumer) {
        System.out.println("开始执行");
        String str = "Hello World!";
        System.out.println(str);
        consumer.accept(str);
    }

    public static void b(Consumer<String> consumer,Consumer<String> consumer2) {
        System.out.println("开始执行");
        consumer.andThen(consumer2).accept("Hello World!");
    }

}

